package com.sx.gongzhong.utils;

import android.content.Context;

import com.sx.gongzhong.model.PublicTotalBean;
import com.sx.gongzhong.pest.PublicTotalPest;
import com.sx.gongzhong.view.IPublicTotalView;

import java.util.List;

import xiaofei.library.datastorage.DataStorageFactory;
import xiaofei.library.datastorage.IDataStorage;

/**
 * Created by XZY on 2018/1/10.
 * 初始话数据的类
 */
public class InitData implements IPublicTotalView{

    private Context context;
    private IDataStorage dataStorage;
    public InitData(Context context) {
        this.context = context;
        dataStorage= DataStorageFactory.getInstance(
                context.getApplicationContext(),
                DataStorageFactory.TYPE_DATABASE);
    }

    public void loadData(){
        new PublicTotalPest(this).getPublicTotal();
    }


    @Override
    public void showError(String message) {
        ToastUtils.showToast(context,message);
    }

    @Override
    public void getPublicTotal(List<PublicTotalBean> beanList) {
        if (beanList!=null){
            dataStorage.storeOrUpdate(beanList);
        }
    }
}
